package bite20220409;

import com.sun.javafx.scene.control.behavior.TextBinding;

class Monkey{
    int money = 9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}


class Person implements Cloneable{
    public int id = 1234;
    public Monkey m = new Monkey();
    @Override
    public String toString() {
        return "Person{" +
                "id='" + id + '\'' +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        tmp.m = (Monkey) this.m.clone();
        return super.clone();
    }
}

public class ClonableDemo {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        Person person2 = (Person)person1.clone();//产生副本,浅拷贝
        System.out.println(person2);
    }
}
